/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2023-10-23 19:24:16
 * @LastEditors: TT
 * @LastEditTime: 2023-10-30 09:54:25
 */
import 'package:flutter/material.dart';
import 'package:hzy_project_template/commpontents/commpontents_index.dart';
import 'package:hzy_project_template/config/config_index.dart';
import 'package:hzy_project_template/controllers/user_c.dart';
import 'package:hzy_project_template/pages/my/config/config_index.dart';
import 'package:hzy_project_template/pages/my/config/my_normal_config.dart';
import 'package:hzy_project_template/base_ui_config/base_ui_config_index.dart';

class MyGeneralV extends CommonLessV {
  MyGeneralV({Key? key}) : super(key: key);
  @override
  String? get appBarTitle => MyLaunchIdConfig.general.tr;

  final MyGeneralC controller = Get.put(MyGeneralC());

  @override
  Widget createBody({
    required BuildContext context,
    BoxConstraints? constraints,
  }) {
    Widget body = configListWidget();

    body = Column(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        body,
        configLoginOutBtn(),
      ],
    );
    return body;
  }

  /// 创建列表
  configListWidget() {
    Widget body = ListView.builder(
      itemBuilder: configItemBuilder,
      itemCount: controller.config.length,
    );
    body = Expanded(
      child: body,
    );
    return body;
  }

  /// 创建列表item
  Widget configItemBuilder(
    BuildContext context,
    int index,
  ) {
    HzyNormalItemModel itemModel = controller.config[index];
    Widget body = configNormalDarkItemWidget(
      itemModel: itemModel,
      onOtherTap: (itemModel) {
        controller.tapItemOtherEvent(
          itemModel: itemModel,
        );
      },
    );
    return body;
  }

  /// 创建退出登录按钮
  configLoginOutBtn() {
    Widget body = configOnlyTextBtnWidget(
      text: NoteLauncIdConfig.loginOut.tr,
      bgColor: HzyCommonColor().colefedf3,
      textColor: HzyCommonColor().col666666,
      height: 48.w,
      tapCall: () {
        controller.tapLoginOut();
      },
    );
    body = Padding(
      padding: EdgeInsets.all(20.w),
      child: body,
    );
    return body;
  }
}

class MyGeneralC extends CommonGetXController {
  // --------- 属性 --------- //

  List<HzyNormalItemModel> get config => MyNormalConfig().generalList;

  String msg = MyNormalConfig.configDarkModelIsOpen();
  // --------- 生命周期  --------- //

  // --------- 数据处理  --------- //

  // --------- 触发事件  --------- //

  /// 点击item 触发其他事件
  /// 不包含路由跳转
  tapItemOtherEvent({required HzyNormalItemModel itemModel}) {}

  /// 点击退出登录
  tapLoginOut() async {
    await UserC.current.logOut();
    jumpToRootWithNamePage(
      context: Get.context!,
      name: PageIdConfig.index,
    );
  }
}
